﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_ProductList : ASPXBaseClass
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["User"].ToString() != "admin")
        {
            Response.Redirect("~/Admin/RedirectLogin.htm");
        }
        if (!IsPostBack)
        {
            BindDrp();
            BindRpt();
        }
    }

    void BindRpt()
    {
        GZ.Entity.EProductInfo obj = new GZ.Entity.EProductInfo();
        if (this.txtProductId.Text.Length > 0)
        {
            obj.Id = Convert.ToInt16(this.txtProductId.Text.Trim());
        }
        if (this.txtProductName.Text.Length > 0)
        {
            obj.ProductName = this.txtProductName.Text;
        }
        if (this.txtProductPrice.Text.Length > 0)
        {
            obj.Price = Convert.ToDecimal(this.txtProductPrice.Text.Trim());
        }
        if (this.txtProductStyle.Text.Length > 0)
        {
            obj.ProductStyle = this.txtProductStyle.Text;
        }
        if (this.drpCategory.SelectedValue != "-1")
        {
            obj.CategoryId = Convert.ToInt16(this.drpCategory.SelectedValue);
        }
        if (this.drpShelvesState.SelectedValue != "-1")
        {
            obj.IsShelves = Convert.ToInt16(this.drpShelvesState.SelectedValue);
        }
        this.rptProductList.DataSource = obj.GetProductListByCondition(obj);
        this.rptProductList.DataBind();
    }

    /// <summary>
    /// 绑定下拉
    /// </summary>
    void BindDrp()
    {
        GZ.Common.DataBindHelper.BindDropDownList("CategoryName", "Id", new GZ.Entity.ECategory().GetCategory(), this.drpCategory);
        this.drpShelvesState.Items.Insert(0, new ListItem("请选择", "-1"));
        this.drpCategory.Items.Insert(0, new ListItem("请选择", "-1"));
    }


    /// <summary>
    /// 查询事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnQuery_Click(object sender, EventArgs e)
    {
        BindRpt();
    }


    /// <summary>
    /// 行绑定事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void rptProductList_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            HiddenField HIsShelves = e.Item.FindControl("HIsShelves") as HiddenField;
            Button btnUpShelves = e.Item.FindControl("btnUpShelves") as Button;
            Button btnDownShelves = e.Item.FindControl("btnDownShelves") as Button;
            btnUpShelves.Visible = false;
            btnDownShelves.Visible = false;
            int IsShelves = Convert.ToInt16(HIsShelves.Value);
            if (IsShelves > 0)
            {
                btnDownShelves.Visible = true;
            }
            else
            {
                btnUpShelves.Visible = true;
            }
        }
    }

    /// <summary>
    /// 行事件
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    protected void rptProductList_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        int Id = Convert.ToInt16(e.CommandArgument);
        if (e.CommandName == "UpShelves")
        {
            new GZ.Entity.EProductInfo().UpShelves(Id);
        }
        if (e.CommandName == "DownShelves")
        {
            new GZ.Entity.EProductInfo().DownShelves(Id);
        }
        if (e.CommandName == "Del")
        {
            new GZ.Entity.EProductInfo().Del(Id);
        }
        
        BindRpt();
    }
}